package edu.hunan.cxb18.controller;

import edu.hunan.cxb18.pojo.Product;
import edu.hunan.cxb18.result.CommonTypeResult;
import edu.hunan.cxb18.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author AuthorName
 * @create 2020-04-22 11:45
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/hots")
    public List<Product> test(){
      return productService.queryByHot(6);
    }
    @GetMapping("/news")
    public List<Product> news(){
        return productService.queryByNew(5);
    }
    @GetMapping("/indexProducts")
    public CommonTypeResult indexProducts(){
        Map<String, List<Product>> stringListMap = productService.loadIndexProducts(4);
        return CommonTypeResult.creat(stringListMap);
    }
    @GetMapping("/Byid")
    public CommonTypeResult Byid(@RequestParam("id") int id){
        return CommonTypeResult.creat(productService.queryById(id));
    }
}
